from numpy import float64

class TopologicalIndex:
    
    def __init__(self, function):
        self.function = function
        
    def value(self, graph):
        s = 0
        for edge in graph.edges():
            du = len(graph.neighbors(edge[0]))
            dv = len(graph.neighbors(edge[1]))
            s += self.function(float64(du), float64(dv))
        return s
    
    def name(self):
        return self.function.__name__